﻿using System.Collections.Generic;
using System.Web.Mvc;
using PagedList;
using SmallBusinessKit.Interfaces;
using SmallBusinessKit.Models.NonEntities;
using SmallBusinessKit.ViewModels;
using WebGrease.Css.Extensions;

namespace SmallBusinessKit.Controllers
{
    public class PeopleController : BaseController
    {
        #region Properties

        private readonly IPersonDomain _personDomain;

        #endregion

        #region Methods

        public PeopleController(IPersonDomain personDomain)
        {
            _personDomain = personDomain;
        }

        [Route("AboutUs")]
        public ViewResult AboutUs()
        {
            return View();
        }

        [Route("OurEmployees/{page?}")]
        public ActionResult OurEmployees(int? page)
        {
            const int pageSize = 2;
            var pageNumber     = (page ?? 1);
            var results        = _personDomain.GetAllPersonsList();

            var people = new List<PersonDto>();

            results.ForEach(i => people.Add(
                                            new PersonDto
                                            {
                                                FullName     = $"{i.FirstName} {i.LastName}",
                                                Title        = i.Title,
                                                Desc         = i.Desc,
                                                Phone        = $"({i.Phone.Substring(0, 3)}) {i.Phone.Substring(3, 3)}-{i.Phone.Substring(6)}",
                                                Fax          = $"({i.Fax.Substring(0, 3)}) {i.Fax.Substring(3, 3)}-{i.Fax.Substring(6)}",
                                                Email        = i.Email,
                                                ImageUrl     = i.ImageUrl,
                                                ImageAltText = i.ImageAltText
                                            }));

            var viewModel = new PeopleViewModel
            {
                People = people.ToPagedList(pageNumber, pageSize)
            };

            if (Request.IsAjaxRequest())
            {
                return PartialView("_People", people.ToPagedList(pageNumber, pageSize));
            }

            return View(viewModel);
        }

        [Route("OurHistory")]
        public ViewResult OurHistory()
        {
            return View();
        }

        [Route("Contact")]
        public ViewResult Contact()
        {
            return View();
        }

        [Route("Org")]
        public ViewResult Org()
        {
            return View();
        }

        [ChildActionOnly]
        public PartialViewResult AboutMenu()
        {
            return PartialView("_AboutMenu");
        }

        #endregion
    }
}